package com.ssh;

import java.util.ArrayList;
import java.util.List;

public class Permute_46 {
	public static void main(String[] args) {
		int[] nums = {1,2,3};
		permute(nums);
		/*List<List<Integer>> list = new ArrayList<List<Integer>>();
		List<Integer> l = new ArrayList<Integer>();
		l.add(11);
		list.add(new ArrayList<>(l));
		System.out.println(list);
		l.add(22);
		System.out.println(l);
		System.out.println(list);*/
		
	}
	public static List<List<Integer>> permute(int[] nums) {
		List<List<Integer>> list = new ArrayList<List<Integer>>();
		l(nums,list,new ArrayList<>());
		System.out.println(list);
		return list;
	}
	private static void l (int[] nums, List<List<Integer>> list,List<Integer> l1) {
		if (l1.size() == nums.length) {
			list.add(new ArrayList<>(l1));

			System.out.println("list="+list);
		}
		for (int i = 0; i < nums.length; i++) {
			System.out.println("i="+i);
			
			if (l1.contains(nums[i])) {
				continue;
			}
			
			l1.add(nums[i]);
			
			System.out.println("nums[i]="+nums[i]);
			System.out.println("l1="+l1);
			
			l(nums,list,l1);
			l1.remove(l1.size()-1);
			
			System.out.println("l11="+l1);
		}
		
	}
}
	